home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / wwdos_02.zip / WW2-7 < prev    next >
Text File  |  1995-01-16  |  11KB  |  188 lines

  1.  
  2.         PROGRAMMING NOTES                   A WindoWatch Series
  3.  
  4.                     WINDOWS  ASPECT: A Scripting Language
  5.  
  6.  A Tutorial - Part Two for Procomm for Windows v.2 GHOST BBS v.3.20
  7.                        (c) 1995 by Gregg Hommel
  8.  
  9.  
  10.  When last we left our intrepid  hero, George, he was just starting to
  11.  learn about scripting in the Windows Aspect (Wasp) language of Procomm
  12.  Plus for Windows 2.0, by writing a very simple log on script.
  13.  
  14.  Let's give him a little time to get in some practice, before we pick up
  15.  his saga and look at something that we touched on briefly in the last
  16.  column, i.e. the nature of a script. What we said way back then was this..
  17.  
  18.  "In Wasp, a script is a series of commands which Procomm Plus for
  19.  Windows will read when told to, and execute as specified.  These
  20.  commands are written using a particular form, following a designated
  21.  syntax, and instruct Procomm Plus for Windows to perform various tasks
  22.  at specified times, and in a specified order."
  23.  
  24.  Now, to some of you, that just might look like a rather simplified
  25.  definition of a computer program. This could be because a script can be
  26.  considered just that, and those of us who write scripts generally
  27.  consider what we do as programming.
  28.  
  29.  Basically, I suppose that every programmer has his own idea of what
  30.  makes up good programming practice. In my opinion, this good practice
  31.  consists of two basic routines : 1) planning in advance what you want the
  32.  script to accomplish, and roughly how it might do so, and 2) writing the
  33.  code you need in a modular fashion. Let me explain.....
  34.  
  35.  It is quite difficult to write code to have a script do what needs be
  36.  done next, when you, the author, have no idea what you want it to do
  37.  next. The code won't "get anywhere" if you, the programmer, have no
  38.  idea where you expect it to go.
  39.  
  40.  Generally, before I begin work on any code,  I attempt to write out, in
  41.  English, what I want the code to  accomplish, and where I want it to
  42.  finish when done. This gives me a basic word picture of what I hope the
  43.  code accomplish. To relate this directly to Wasp, it also helps to
  44.  force you to look at what is happening on the terminal with a more
  45.  careful eye, as you attempt to follow the events on the screen in order
  46.  to create that word picture.
  47.  
  48.  But... the first rule is to start out simply.  Don't get too fancy, and
  49.  don't try to do too much with the first draft of a script.  I prefer a
  50.  modular approach to script writing, where one can add features and
  51.  functions simply by adding a new procedure to a basic script. In this
  52.  way, a first draft script can be kept quite simple, and then have other
  53.  routines added to it as they are written and tested.
  54.  
  55.  However, this does not preclude increasing the size of the main (or
  56.  any) procedure. Once a procedure has been tested and found to work
  57.  properly, particularly if it is to be called only one time, I will
  58.  simplify the structure of the script by removing it as a separate
  59.  procedure.  It is then added to the procedure where it was called
  60.  initially, making it part of that procedure.
  61.  
  62.  Basically, when I begin work on a new script, or on a new procedure to
  63.  be added to a script, I make sure of two things... 1) that I have lots
  64.  of paper to rough out in English, flow chart, and code information,
  65.  and, 2) that I have plenty of disk space available for various versions
  66.  of the code being tested along with backups of the new code, just in
  67.  case!
  68.  
  69.  I remember one time when I was away from my computer for the weekend
  70.  and brought with me a printout of the code I was working on, and a pad
  71.  of paper to use when working on the modified code. My daughters
  72.  complained bitterly that I had to  have destroyed three trees writing
  73.  that relatively small piece of code because I used so much paper writing
  74.  it. This brings up another routine that I use frequently. Rather than
  75.  physically testing the code while on line, I often use diagrams, flow
  76.  charts, and logical analysis to work out on paper, what should happen.
  77.  This procedure will test the logic of the script before actually
  78.  compiling it and running the code.
  79.  
  80.  The logic of the script can be supremely important when trying to track
  81.  down a bug or mistaken action. One of the main benefits of using English
  82.  coding, and flow charting a script is that it tends to improve the logic
  83.  of that script. Rather than bouncing here and there, from one procedure
  84.  to another, it becomes easier to write the various procedures and
  85.  routines in a more logical fashion. This makes the script easier to
  86.  follow later, if a problem develops, or you choose to change some
  87.  section of it.  A logical arrangement of sub-procedures and routines
  88.  within a procedure makes it far easier to locate a section of code
  89.  should you decide you want (or need) to change.
  90.  
  91.  To that end, I also attempt to use descriptive variable names and
  92.  procedure/function names, where ever possible. As example, in my PCB
  93.  Freedom script, the procedure which does the physical dialing of a
  94.  system and manages the on line functions is called "proc dial_boards".
  95.  The procedure which it creates, a dialog box to edit system settings
  96.  while off line, is called "proc edit_dlgs". The routine to add a new
  97.  system to the configuration list is called "proc add_item".
  98.  
  99.  I am sure that you can see how this might prove advantageous. On a
  100.  little script like a basic log on script, this is not of great
  101.  importance, as the script is fairly short.  My GHOST BBS script is
  102.  currently around 9,500 lines of Wasp code.  Locating a particular
  103.  section within that 9,500 lines can be quite difficult without some
  104.  sign posts. I try to use descriptive variable and procedure names, with
  105.  a logical connection to what they are for, as my sign posts.
  106.  
  107.  I also use the search and replace feature of my editor as frequently as
  108.  possible. No, I don't use the editor shipped with PCP/Win 2.0... I am a
  109.  long time Norton DeskTop user, and simply prefer the familiar, Norton's
  110.  DeskTop Editor. Often times, a variable, or procedure may start life
  111.  with a particular name, descriptive of it's purpose and place within
  112.  the logic of the script. However, as the script takes on new features
  113.  and functions, that descriptive name may no longer be valid, or useful.
  114.  When this happens, search and replace allows for easy change of one
  115.  name or variable in use into another that is more informative.
  116.  
  117.  The thing to remember is that there are no set rules for methods or
  118.  procedures to write a good script. What works best for one code maven
  119.  may be deadly to another. I know my old CompScience Prof. from many
  120.  years back would probably have a fit about that comment.  He constantly
  121.  emphasized following traditional rules  when coding. However, in the
  122.  real world, I have found that some of those rules donÆt always work.
  123.  
  124.  That Prof. used to regularly tell us to never use a GOTO label, but to
  125.  always call a sub-routine instead. Theoretically, this may work, but in
  126.  the real world, there are many occasions when you do not want the
  127.  script to return to a given spot, but rather  to branch off through a
  128.  different set of code. GOTO works rather well for this, while calling a
  129.  sub-routine can be tricky to do the same sort of thing. Since Wasp is
  130.  neither Fortran nor Cobol, or do I run Procomm on a mainframe, the
  131.  rules he used to drill into us are not necessarily applicable.
  132.  
  133.  There is another thing that I find important when breaking the rules...
  134.  you just might discover something that helps execute the code! The
  135.  trick is that, sometimes, what conventional wisdom -the rules says
  136.  can't be done, -  just might be possible. But you will never discover
  137.  these code segments if you follow all of the rules. In both FREEDOM and
  138.  GHOST, there are several bits of code which, when first written,  were
  139.  discarded because examination on paper proved  that they wouldnÆt do.
  140.  But, when all else failed, or the conventional methods grew too
  141.  cumbersome, I would invariably fall back on the "impossible" code, and
  142.  generally, found that what appeared impossible on paper, worked quite
  143.  well when compiled.
  144.  
  145.  Remember that there is a corollary to this "trick.  Sometimes what
  146.  appears, at first test, to work, is really impossible and can bite when
  147.  you least expect it.  One pitfall to being a ground breaker is that
  148.  sometimes you find that, instead of breaking new ground, you are over
  149.  the edge of the cliff  with an anvil for a parachute.
  150.  
  151.  Never discount the  impossible... fairly early in the beta of FREEDOM,
  152.  I ran into a problem with some very strange responses being sent by the
  153.  script.  The code was written to delete all characters from the string
  154.  variable resulting in a null string and nothing being sent. When I
  155.  discussed it with the folks from Datastorm, I was told that what I
  156.  claimed to have happening was impossible, and that deleting one by one,
  157.  the characters of a string HAD to result in a null string when the last
  158.  character was deleted.
  159.  
  160.  Further testing, careful observation and notes of what was being sent
  161.  when nothing should have been sent, showed me that somehow the string,
  162.  once all characters were deleted, was being assigned a value. That
  163.  value seemed to be the central six characters from the LAST string
  164.  variable accessed before the current string variable had it's last
  165.  character deleted !! Does this make sense?? The solution: When the last
  166.  character was supposed to be deleted from the string, instead of
  167.  actually deleting it, I began assigning the system variable $NULLSTR to
  168.  the string variable. Now, impossible or not, the string variable
  169.  actually was a null when I wanted and expected it to be one.
  170.  
  171.  In other words, never say never, and always suspect that what is not
  172.  possible for a script to do, just may be possible.  Further, never turn
  173.  your back on a  completed  and  fully tested  script.... they can be
  174.  mean, vicious and downright despicable!
  175.  
  176.  I suppose that is enough rambling on and lecturing for now... in our
  177.  next column, we'll go back to dear old George, and help him develop his
  178.  simple log on script into something more generic, and more useful.
  179.  
  180.  Gregg Hommel is a communications consultant for Delrina. He hosts
  181.  several of the Procomm conferences and co-hosts the Rime Windows
  182.  conference. He has been a Procomm beta tester and is the author of the
  183.  Aspect scripts Freedom and Ghost.
  184.  
  185.  
  186.                                    ww
  187.  
  188.